package ma.fsm.arda.command.strategy;

import ma.fsm.arda.command.Command;

public class Explorer implements AutoStrategy {
	private Command command;
	private boolean started = true;

	public Explorer(Command command) {
		this.command = command;
	}

	public Explorer() {

	}

	@Override
	public void execute() {
		if (!command.isAuto()) {
			command.setAuto(true);

			while (started) {
				System.out.println("loop..");

				Short sensorValueA = command.sensorA();
				Short sensorValueB = command.sensorB();

				System.out.println(sensorValueA);
				System.out.println(sensorValueB);

				if ((sensorValueA > 200) && (sensorValueB < 200)) {
					command.goLeft();
				}
				if ((sensorValueB > 200) && (sensorValueA < 200)) {
					command.goRight();
				}

				if ((sensorValueA < 200) && (sensorValueB < 200)) {
					command.goForward();
				}

				if ((sensorValueA > 200) && (sensorValueB > 200)) {
					if (sensorValueA > sensorValueB) {
						command.spinLeft();
					}
					if (sensorValueA < sensorValueB) {
						command.spinRight();
					}

				}

			}
			command.stop();
			command.setAuto(false);
			System.out.println("loop out");
		}
	}

	@Override
	public void stop() {
		System.out.println("STOPED");
		started = false;

	}

	public Command getCommand() {
		return command;
	}

	public void setCommand(Command command) {
		this.command = command;
	}

}
